package com.caokele.demo.auth.config;

import com.alibaba.cloud.nacos.NacosConfigManager;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.AbstractListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
public class ConfigAndSignListener implements InitializingBean {
    @Autowired
    private NacosConfigManager nacosConfigManager;

    @Override
    public void afterPropertiesSet() throws Exception {
        ConfigService configService = nacosConfigManager.getConfigService();
        configService.getConfigAndSignListener("auth.properties", "DEFAULT_GROUP", 10000L, new AbstractListener() {
            @Override
            public void receiveConfigInfo(String content) {
                log.info("receiveConfigInfo:" + content);
            }
        });
    }
}
